package com.wesleyone.wifiusb.index;

import com.jfinal.core.Controller;
import com.jfinal.upload.UploadFile;
import com.wesleyone.wifiusb.common.MyConfig;
import com.wesleyone.wifiusb.util.CommonTools;

import java.io.File;

/**
 * 首页
 */
public class IndexController extends Controller {


	public void index() {
		String content = "http://" + System.getProperty("undertow.host") + ":" + System.getProperty("undertow.port");
		setAttr("HOST_URL",content);
		render("index.html");
	}

	/**
	 * 上传文件
	 */
	public void uploadFile(){
		UploadFile file = getFile();
		String originalFileName = file.getOriginalFileName();
		int i = file.getOriginalFileName().lastIndexOf(".")+1;
		String fileName = originalFileName;
		String newFilePath = MyConfig.FILE_PATH+ File.separator+fileName;
		file.getFile().renameTo(new File(newFilePath));

		setAttr("code","00");
		setAttr("name",fileName);
		renderJson();
		CommonTools.openFold(MyConfig.FILE_PATH);
	}
}



